﻿@using System.Diagnostics;
@using NewLife.Common;
@using NewLife.Cube.Admin;
@{
    var fs = Model as List<FileItem>;
    var r = ViewBag.Current as String;
    var clips = ViewBag.Clip as ICollection<FileItem>;
}

<div class="card card-custom">
    <div class="card-header pt-5 pb-0">
        <div class="form-inline">
            <form action="~/Admin/File" id="tool" method="post">
                <div class="input-group" style="float:left;">
                    <span class="input-group-addon">
                        <i class="ace-icon fa fa-check"></i>
                    </span>
                    <input name="r" type="search" id="r" value="@r" class="form-control" placeholder="当前路径" />
                    <span class="input-group-btn">
                        <button type="submit" class="btn btn-primary btn-sm">
                            <span class="glyphicon glyphicon-folder-open icon-on-right bigger-110"></span>
                            打开
                        </button>
                    </span>
                </div>
                <div class="input-group" style="float:left;padding-top:5px;margin-left:15px;">
                    <span class="input-group-addon">
                        <i class="glyphicon glyphicon-file"></i>
                    </span>
                    <input name="file" type="file" id="file" placeholder="上传文件" />
                    @*<div class="uppy" id="kt_uppy_5">
                        <div class="uppy-wrapper"></div>
                        <div class="uppy-list"></div>
                        <div class="uppy-status"></div>
                        <div class="uppy-informer uppy-informer-min"></div>
                    </div>*@
                    <span class="input-group-btn">
                        <button type="submit" class="btn btn-success btn-sm" onclick="$('#tool').attr('action', '/Admin/File/Upload');$('#tool').attr('enctype', 'multipart/form-data'); return true;">
                            <span class="glyphicon glyphicon-plus icon-on-right bigger-110"></span>
                            上传
                        </button>
                    </span>
                </div>
                @if (clips.Count > 0)
                {
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="glyphicon glyphicon-floppy-disk" title="剪切板共有 @clips.Count 项">@clips.Count</i>
                        </span>
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-pink btn-sm" onclick="location.href = '/Admin/File/Paste?r=@r';">
                                <span class="glyphicon glyphicon-floppy-save icon-on-right bigger-110"></span>
                                粘贴
                            </button>
                        </span>
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-gray btn-sm" onclick="location.href = '/Admin/File/Move?r=@r';">
                                <span class="glyphicon glyphicon-floppy-save icon-on-right bigger-110"></span>
                                移动
                            </button>
                        </span>
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-yellow btn-sm" onclick="location.href = '/Admin/File/ClearClipboard?r=@r';">
                                <span class="glyphicon glyphicon-retweet icon-on-right bigger-110"></span>
                                清空
                            </button>
                        </span>
                    </div>
                }
            </form>
        </div>
    </div>
    <div class="card-body pt-5">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th><a href="~/Admin/File?r=@r&sort=name">名称</a></th>
                    <th class="text-right"><a href="~/Admin/File?r=@r&sort=size">大小</a></th>
                    <th class="text-center"><a href="~/Admin/File?r=@r&sort=lastwrite">修改时间</a></th>
                    <th class="text-center">复制</th>
                    <th class="text-center">压缩</th>
                    <th class="text-center">删除</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in fs)
                {
                    <tr>
                        @if (item.Directory)
                        {
                            <td>&nbsp;&nbsp;<a href="~/Admin/File?r=@item.FullName" title="进入目录">@item.Name</a></td>
                        }
                        else
                        {
                            <td>&nbsp;&nbsp;<a href="~/Admin/File/Download?r=@item.FullName" title="下载文件">@item.Name</a></td>
                        }
                        <td class="text-right">@item.Size</td>
                        <td class="text-center">@item.LastWrite.ToFullString("")</td>
                        <td class="text-center">
                            @if (!clips.Any(e => e.FullName == item.FullName))
                            {
                                <a href="~/Admin/File/Copy?r=@r&f=@item.FullName" title="复制到剪切板，然后去目标目录粘贴">复制</a>
                            }
                            else
                            {
                                <a href="~/Admin/File/CancelCopy?r=@r&f=@item.FullName" title="从剪切板移除">取消复制</a>
                            }
                        </td>
                        @if (item.Name.EndsWithIgnoreCase(".zip"))
                        {
                            <td class="text-center"><a href="~/Admin/File/Decompress?r=@item.FullName" title="解压缩到当前目录">解压缩</a></td>
                        }
                        else
                        {
                            <td class="text-center"><a href="~/Admin/File/Compress?r=@item.FullName" title="压缩到当前目录，加上时间后缀">压缩</a></td>
                        }
                        <td class="text-center"><a href="~/Admin/File/Delete?r=@item.FullName" onclick="return confirm('确认删除？');">删除</a></td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>

